package com.laoli.controller;

import com.laoli.entity.Course;
import com.laoli.entity.CourseDTO;
import com.laoli.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @BelongsProject: edu-lagou
 * @Author: GuoAn.Sun
 * @CreateTime: 2020-10-16 16:17
 * @Description:
 */
@RestController
@RequestMapping("course")
@CrossOrigin //跨域
public class CourseController {
    @Autowired
    private CourseService courseService;
    @GetMapping("getAllCourse")
    public List<CourseDTO> getAllCourse() {
//        ExecutorService es = Executors.newFixedThreadPool(20);
//        for(int i = 1 ;i<=20;i++){
//            es.submit(new Runnable() {
//                @Override
//                public void run() {
//                    courseService.getAllCourse();
//                }
//            });
//        }
        return courseService.getAllCourse();
    }

    @GetMapping("getCourseById/{courseid}")
    public  CourseDTO getCourseById(@PathVariable("courseid") Integer courseid) {
        return courseService.getCourseById(courseid);
    }

    @GetMapping("getCoursesByUserId")
    public List<CourseDTO> getCoursesByUserId(Integer userid) {
        return courseService.getCoursesByUserId(userid);
    }
}
